var NEWS = require('../../../class/news/news.c');

module.exports = {
    prefix: '/admin/news/',
    post: {
        'create': {
            des: {
                name: 'createNews',
                content: '创建资讯',
                params: [
                    {
                        key: 'title',
                        type: 'String,资讯标题'
                    },
                    {
                        key: 'content',
                        type: 'String|HTMLDOC,资讯内容'
                    },
                    {
                        key: 'preview_url',
                        type: 'String|uri,预览图'
                    }
                ]
            },
            method: function* () {
                var self = this;
                try {
                    var data = self.request.body;
                    var _n = yield new NEWS(data).save();
                    self.body = _n;
                } catch (e) {
                    self.body = printError(e);
                }
            }
        }
    },
    put: {
        'update': {
            des: {
                name: 'updateNews',
                content: '更新资讯',
                params: [
                    {
                        key: 'newsObject',
                        type: 'newObject,资讯对象'
                    }
                ]
            },
            method: function* () {
                var self = this;
                try {
                    var data = self.request.body;
                    var _res = yield NEWS.update(data);
                    self.body = _res;
                } catch (e) {
                    self.body = printError(e);
                }
            }
        }
    },
    delete: {
        'delete/:_id': {
            des: {
                name: 'deleteNews',
                content: '删除资讯',
                params: [
                    {
                        params: '_id',
                        type: 'String,资讯_id'
                    }
                ]
            },
            method: function* () {
                var self = this;
                try {
                    var _id = self.params._id;
                    var _res = yield NEWS.delete(_id);
                    self.body = _res;
                } catch (e) {
                    self.body = printError(e);
                }
            }
        }
    }
}